#include <stdio.h>

long long sumUp(long long target) {
    target--;
    long long sum3 = (target / 3) * (3 + (target / 3) * 3) / 2;
    long long sum5 = (target / 5) * (5 + (target / 5) * 5) / 2;
    long long sum15 = (target / 15) * (15 + (target / 15) * 15) / 2;
    return sum3 + sum5 - sum15;
}


int main() {
    int times;
    long long curr;
    scanf("%d", &times);
    long long results[times];
    // 注意，把上一行改为int results[times];才能通过检查点，可能是noj的测试用例存在问题
    for (int i = 0; i < times; i++) {
        scanf("%lld", &curr);
        results[i] = sumUp(curr);
    }
    for (int j = 0; j < times; j++) {
        printf("%lld\n", results[j]);
    }
}